home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4893 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mudskipper.cac.psu.edu!user
  2. From: fcusack@tdx.org (frank.)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: simple code, argc, argv, strcmp()
  5. Date: Wed, 07 Feb 1996 15:19:20 -0400
  6. Organization: Penn State University, Center for Academic Computing
  7. Message-ID: <fcusack-0702961519200001@mudskipper.cac.psu.edu>
  8. References: <11f7cc$17261a.3b3@daprez> <4etj7c$bma@news.iag.net> <fcusack-0202961621470001@mudskipper.cac.psu.edu> <31177C77.167EB0E7@texas.net>
  9. NNTP-Posting-Host: mudskipper.cac.psu.edu
  10.  
  11. In article <31177C77.167EB0E7@texas.net>, Michael Douglass
  12. <mikedoug@texas.net> wrote:
  13.  
  14. > > > >int main (int argc, char **argv) {
  15. > > > >
  16. > > > >  void Usage   (void);
  17. > > > >  void Encode (int, char **);
  18. > > > >  void Decode (int, char **);
  19. > > > >
  20. > > > >  if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
  21. > > > >    Usage();
  22. > > > >  }
  23. > > > <snip>
  24. > > argv[1] is always guaranteed to exist. It is simply NULL if there were no
  25. > > arguments.
  26. > Even if this is so... You still do *not* want to call strcmp with a NULL
  27. pointer
  28. > now do we?  Does that not make your argument moot, and make the previous point
  29. > that you should always check argc to make sure that you *have* at least
  30. one argument
  31. > a very good argument?
  32.  
  33. well, a) argv[1] is not guaranteed to exist. Sorry for that mistake.
  34.  
  35. b) I meant that if argv[0] is passed (and is the command name), then
  36.    argv[1] is a pointer to a null string, not a null pointer.
  37. ~Frank
  38.  -- I am Pentium of Borg.  Division is futile.  You will be approximated. --
  39.  --   If you build it, they will come --> http://www.tdx.org/~fcusack/    --
  40.  -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F  3F 64 80 65 8B 0F F9 EA --
  41.